import columnService from '@/global/service/columnService.js';
import DataStore from '@/global/storage';
import utils from '../global/utils';


const page = [
    // {
    //     path: '/login',
    //     component: () => import('@/views/Login.vue'),
    //     name: 'Login'
    // },
    {
        path: '/',
        name: 'Root',
        component: () => import('@/components/layout/BasicLayout.vue'),
        // redirect: { name: "Home" },
        children: []
    },
    {
        path: '/404',
        name: 'Error404',
        component: () => import('@/views/Error404.vue')
    }
];

export default page.map(async (routes) => {
    if (routes.children) {

        const { code, data } = await columnService.getList();

        if (code === 200) {
            routes.children = utils.addRouterAuth(data);
            let menus = [];

            for (let i in data) {
                if (data[i].pid === 0) {
                    let name = data[i].name;
                    data[i].name = name.charAt(0).toUpperCase() + name.slice(1);
                    menus.push(data[i]);
                }
            }

            DataStore.storage.set('menus', menus);
        }
    }

    return routes;
});
